package com.wngbms.feigndemo.service;

import com.alibaba.ttl.TtlRunnable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
@Component
public class TraceServ {

//    @Autowired
//    private ExecutorService proxyExecutor;

    ExecutorService proxyExecutor = Executors.newFixedThreadPool(10);

    public TraceServ() {
//        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(executorService);
//        proxyFactory.setExposeProxy(true);
//        proxyFactory.addAdvice(new MethodBeforeAdvice() {
//            @Override
//            public void before(Method method, Object[] args, Object target) throws Throwable {
//                if ("submit".equals(method.getName()) && args.length == 1) {
//                    Object proxy = AopContext.currentProxy();
//                    String traceId = MDC.get("traceId");
//
//                }
//            }
//        });
    }

    public void doSomething() {
        log.info("I don't want to do anything");

        Runnable runnable = () -> {
            log.info("async log");
        };

        TtlRunnable ttlRunnable = TtlRunnable.get(runnable);

        for (int i = 0; i < 10; i++) {
            proxyExecutor.submit(ttlRunnable);
        }

    }

}
